/***********************************************************************************************************************************
 * Name:	SSRS_FixDataSource.sql
 * Author:	Frank Figearo (frank.figearo@us.bbaaviation.com|frank@sqlnerd.me)
 * Summary:	Fix reports' broken links to data source.
 */
USE ReportServer;
GO
UPDATE dbo.DataSource
  SET Link= c.ItemID, Flags= Flags | 0x00000002
  FROM dbo.Catalog c INNER JOIN dbo.DataSource ds ON (c.Name = ds.Name)
  WHERE c.Type = 5 AND c.Path LIKE N'/Data Sources/%' AND ds.Flags & 0x00000002 = 0 AND ds.Link IS Null;
GO